package com.inspur.resourcequery.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.inspur.resourcequery.R;
import com.inspur.resourcequery.model.ResData;

public class PhysicsListAdapter extends BaseAdapter {

	private List<ResData> list;
	private Context mContext;

	public PhysicsListAdapter(Context context, List<ResData> list) {
		mContext = context;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewHolder = null;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(mContext).inflate(R.layout.physics_item, null);

			viewHolder.tvLabel = (TextView) convertView.findViewById(R.id.tv_label);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		ResData model = (ResData) list.get(position);
		if(model.getName() == null || "".equals(model.getName()) || "null".equals(model.getName())){
			model.setName("无名称");
		}
		viewHolder.tvLabel.setText(model.getName());
		return convertView;
	}

	final static class ViewHolder {
		TextView tvLabel;
	}
}
